﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace BanSach
{
    public partial class frmBan : Form
    {
        public frmBan()
        {
            InitializeComponent();
        }
        int typeSeach;
        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {
            dataGridView3.DataSource =Ban_BUS.LoadHD();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string mahd = textBox3.Text;
            string masach = textBox4.Text;
            DateTime ngayban = DateTime.Parse(textBox5.Text);
            float giaban = float.Parse(textBox6.Text);
            int sl = int.Parse(textBox1.Text);
            string chietkhau = textBox2.Text;
            string ghichu = textBox7.Text;
            string manv = textBox8.Text;
            string makh = textBox9.Text;
            Ban_DTO ban = new Ban_DTO(mahd, masach, ngayban, giaban, sl, chietkhau, ghichu, manv, makh);
            Ban_BUS.ThemHD(ban);
            dataGridView3.DataSource = Ban_BUS.LoadHD();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = Ban_BUS.LoadHD();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string mahd = textBox18.Text;
            string masach = textBox17.Text;
            DateTime ngayban = DateTime.Parse(textBox15.Text);
            float giaban = float.Parse(textBox13.Text);
            int sl = int.Parse(textBox16.Text);
            string chietkhau = textBox14.Text;
            string ghichu = textBox12.Text;
            string manv = textBox11.Text;
            string makh = textBox10.Text;
            Ban_DTO ban = new Ban_DTO(mahd, masach, ngayban, giaban, sl, chietkhau, ghichu, manv, makh);
            Ban_BUS.SuaHD(ban);
            dataGridView1.DataSource = Ban_BUS.LoadHD();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                typeSeach = 1;
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
            {
                typeSeach = 2;
            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton3.Checked)
            {
                typeSeach = 3;
            }
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton4.Checked)
            {
                typeSeach = 4;
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            switch (typeSeach)
            {
                case 1:
                    {
                        dataGridView2.DataSource = Ban_BUS.TimMaHD(textBox20.Text);
                        break;
                    }
                case 2:
                    {
                        dataGridView2.DataSource = Ban_BUS.TimMaSach(textBox20.Text);
                        break;
                    }
                case 3:
                    {
                        dataGridView2.DataSource = Ban_BUS.TimMaNV(textBox20.Text);
                        break;
                    }
                default:
                    {
                        dataGridView2.DataSource = Ban_BUS.TimMaKH(textBox20.Text);
                        break;
                    }
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Ban_BUS.Xoahd(textBox19.Text);
            dataGridView2.DataSource = Ban_BUS.LoadHD();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            dataGridView2.DataSource = Ban_BUS.LoadHD();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            dataGridView4.DataSource = Ban_BUS.LoadNV();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            dataGridView4.DataSource = Ban_BUS.LoadTienHD();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            dataGridView4.DataSource = Ban_BUS.LoadHD();
        }

        private void radioButton8_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton8.Checked)
            {
                typeSeach = 5;
            }
        }

        private void radioButton7_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton7.Checked)
            {
                typeSeach = 6;
            }
        }

        private void radioButton6_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton6.Checked)
            {
                typeSeach = 7;
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            switch (typeSeach)
            {
                case 5:
                    {
                        dataGridView4.DataSource = Ban_BUS.ThongKeTen(textBox21.Text);
                        break;
                    }
                case 6:
                    {
                        dataGridView4.DataSource = Ban_BUS.ThongKeMaHD(textBox21.Text);
                        break;
                    }
                default:
                    {
                        dataGridView4.DataSource = Ban_BUS.ThongKeTheoNgay(DateTime.Parse(textBox21.Text));
                        break;
                    }
            }
        }
    }
}
